package com.axjy.controller;

import com.axjy.pojo.Menu;
import com.axjy.pojo.User;
import com.axjy.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class ForwardController {

    @Resource
    private PermissionService permissionService;

    @GetMapping("/{folderName}/{fileName}/index")
    public String to(@PathVariable("folderName") String folderName, @PathVariable("fileName") String fileName){
        return folderName+"/"+fileName;
    }

    @GetMapping("/index")
    public String index(HttpSession session,Model model){
       User loginUser= (User) session.getAttribute("loginUser");
       Map<Menu,List<Menu>> menuBar= permissionService.createMenuBar(loginUser);
       model.addAttribute("menuBar",menuBar);
        return "index";
    }

    @GetMapping(value = {"/","/login"})
    public String login(){
        return "login";
    }

}